package com.wxx.example;

import com.wxx.common.Const;
import com.wxx.model.sdk.AliPayModel;
import com.wxx.model.sdk.WeChatModel;
import com.wxx.service.tool.alipay.AlipayService;
import com.wxx.service.tool.wechat.WeChatService;
import com.wxx.util.AppUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping(value = "/test/")
public class Pay {

    @Autowired
    private AlipayService alipayService;
    @Autowired
    private WeChatService weChatService;

    /**
     * 支付宝支付demo
     */
    @RequestMapping(value = "aliPay")
    public Object aliPay(){
        //支付宝
        AliPayModel aliPayModel = new AliPayModel();
        //设置回调地址
        aliPayModel.setNotifyUrl(Const.WEB_URL + "/aliPayCallBack/test");
        //设置主题
        aliPayModel.setSubject("测试");
        //设置订单号
        aliPayModel.setOutTradeNo(AppUtil.getOrderCode());
        //单位元 支付金额
        aliPayModel.setTotalAmount("0.01");
        Map<String, Object> map = alipayService.toAppPay(aliPayModel);
        System.err.println(map.toString());
        return map;
    }

    /**
     * 微信支付demo
     */
    @RequestMapping(value = "wechatPay")
    public Object wechatPay(HttpServletRequest request) throws Exception {
        //微信
        WeChatModel weChatModel = new WeChatModel();
        weChatModel.setBody("测试");
        //微信以分为单位
        weChatModel.setTotal_fee((int) (0.01 * 100));
        weChatModel.setNotify_url(Const.WEB_URL + "/weChatCallBack/test");
        weChatModel.setOut_trade_no(AppUtil.getOrderCode());
        Map<String, Object> map = weChatService.toNativePay(weChatModel, request);
        System.err.println(map.toString());
        return map;
    }
}
